package com.lmt.api;

import com.lmt.base.ResultData;
import com.lmt.entity.search.ResourceSearch;
import com.lmt.service.ResourceService;
import com.lmt.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Date 2018/07/17
 *
 * @author MT-Lin
 */
@RestController
@RequestMapping("/ResourceApi")
public class ResourceApi {

	private final ResourceService resourceService;

	@Autowired
	public ResourceApi(ResourceService resourceService) {
		this.resourceService = resourceService;
	}

	@RequestMapping("/getAuthorInfo")
	public ResultData getAuthorInfo(@RequestBody ResourceSearch resourceSearch){
		return this.resourceService.getAuthorInfo(resourceSearch);
	}

	@RequestMapping("/getResourceDetail")
	public ResultData getResourceDetail(@RequestBody ResourceSearch resourceSearch){
		if (StringUtils.isEmpty(resourceSearch.getId())){
			return ResultUtil.newFail("传入的资源ID为空，无法获取资源详细信息。");
		}
		return this.resourceService.getResourceDetail(resourceSearch.getId());
	}

	@RequestMapping("/getTopFiveByDissertation")
	public ResultData getTopFiveByDissertation() {
		return this.resourceService.getTopFiveByDissertation();
	}

	@RequestMapping("/search")
	public ResultData search(@RequestBody ResourceSearch resourceSearch) {
		return this.resourceService.search(resourceSearch);
	}

	@RequestMapping("/modifyDissertation")
	public ResultData modifyDissertation(@RequestBody ResourceSearch resourceSearch) {
		return this.resourceService.modifyDissertation(resourceSearch);
	}
}
